import React, { useState } from 'react';
import { 
  Card, 
  Typography, 
  Alert,
  Modal, 
  Table, 
  Divider, 
  Tag,
  Form,
} from 'antd';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import RenderButtom from '@/components/RenderButton'

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
    render: text => <a>{text}</a>,
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
  },
  {
    title: 'Tags',
    key: 'tags',
    dataIndex: 'tags',
    render: tags => (
      <span>
        {tags.map(tag => {
          let color = tag.length > 5 ? 'geekblue' : 'green';
          if (tag === 'loser') {
            color = 'volcano';
          }
          return (
            <Tag color={color} key={tag}>
              {tag.toUpperCase()}
            </Tag>
          );
        })}
      </span>
    ),
  },
  {
    title: 'Action',
    key: 'action',
    render: (text, record) => (
      <span>
        <a>Invite {record.name}</a>
        <Divider type="vertical" />
        <a>Delete</a>
      </span>
    ),
  },
];

const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
    tags: ['nice', 'developer'],
  },
  {
    key: '2',
    name: 'Jim Green',
    age: 42,
    address: 'London No. 1 Lake Park',
    tags: ['loser'],
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    address: 'Sidney No. 1 Lake Park',
    tags: ['cool', 'teacher'],
  },
];

const modalContent = () => {
  return (
    <Form>
      <p>Some contents...</p>
      <p>Some contents...</p>
      <p>Some contents...</p>
    </Form>
  )
}

const List = props => {
  // 新增模态框
  const [visible, setVisible] = useState(false)
  const handleModalStatus = () => setVisible(!visible)
  
  const handleBtn = type => {
    // 新增
    if (type == 1) {
      handleModalStatus()
    }
  }
  return (
      <PageHeaderWrapper>
          <RenderButtom click={handleBtn} />
          <Table columns={columns} dataSource={data} />
          <Modal 
            visible={visible}
            onCancel={handleModalStatus}
          >
            {modalContent()}
          </Modal>
      </PageHeaderWrapper>
  )
}
export default List